package com.javaziliao.design.repo;

import com.javaziliao.design.pojo.ProductItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface ProductItemRepository extends JpaRepository<ProductItem, Integer> {

    @Modifying
    @Query(value = "insert into product_item (id,name,pid) " +
            "values ((select max(id)+1 from PRODUCT_ITEM),?1,?2)",nativeQuery = true)
    int addItem(@Param("name") String name,@Param("pid") int pid);

    @Modifying
    @Query(value = "delete from product_item where id=:id or pid=:id",nativeQuery = true)
    int delItem(@Param("id") int id);

    ProductItem findByNameAndPid(String name,int pid);
}
